#include "Scene.h"
#include <algorithm>
#include <functional>
#include "../Core/GlPlatform.h"

namespace Model {
	void Scene::render( View::RenderContext& rx ) {
		float mat_specular[] = { 1, 1, 1, 1 },
			mat_diffuse[] = { 1, 1, 1, 1 },
			mat_ambient[] = { 0.1, 0.1, 0.1, 0.1 },
			mat_shininess = 0,
			light_ambient[] = { .2, .2, .2, .2 },
			light_diffuse[] = { 1, 1, 1, 1 },
			light_position[] = { 0, 10, 0 },
			light_specular[] = { 0, 0, 0 }
		;

		glEnable( GL_LIGHTING );
		glEnable( GL_LIGHT0 );
		glEnable( GL_COLOR_MATERIAL );
		glLightfv( GL_LIGHT0, GL_POSITION, light_position );
		glLightfv( GL_LIGHT0, GL_AMBIENT, light_ambient );
		glLightfv( GL_LIGHT0, GL_DIFFUSE, light_diffuse );
		glLightfv( GL_LIGHT0, GL_SPECULAR, light_specular );
		
		glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
		glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient );
		glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse );
		// glMaterialf( GL_FRONT, GL_SHININESS, mat_shininess );

		using namespace std::placeholders;
		std::for_each( mObjects.begin(), mObjects.end(), 
			std::bind( &Mesh::render, _1, rx ) );
	}

	void Scene::addObject( const std::shared_ptr<Mesh>& ptr ) {
		mObjects.push_back( ptr );
	}

	void Scene::removeObject() {
		mObjects.pop_back();
	}
}